window.FORMAT_DATETIME_DDMMYYHHMM = "MM/dd/yyyy HH:mm";
window.FORMAT_TIME_DDMMYYHHMM = "HH:mm";
(function ($) {
	'use strict';



	/**
	 * format time whis "dd/MM/yyyy HH:mm" to timestramp
	 * @param str
	 * @returns {number}
	 */
	$.stringToTimeStamp = function (str){
		var f = str.split(' ', 2);
		var d = (f[0] ? f[0] : '').split('/', 3);
		var t = (f[1] ? f[1] : '').split(':', 2);
		console.log(d,t)
		return (new Date(
				parseInt(d[2], 10) || null,
				(parseInt(d[0], 10) || 1) - 1,
				parseInt(d[1], 10) || null,
				parseInt(t[0], 10) || null,
				parseInt(t[1], 10) || null
				//parseInt(t[2], 10) || null
			)).getTime();
	}


	/**
	 * put timestamp to string for  dd/MM/yyyy HH:mm
	 * @param timestamp
	 * @returns {string}
	 */
	$.timeStampToString = function(timestamp,format){
		var date = new Date(timestamp);
		format=format.replace(/yyyy|YYYY/,date.getFullYear());
		format=format.replace(/yy|YY/,(date.getYear() % 100)>9?(date.getYear() % 100).toString():'0' + (date.getYear() % 100));

		format=format.replace(/MM/,date.getMonth()>9?date.getMonth().toString():'0' + date.getMonth());
		format=format.replace(/M/g,date.getMonth());

		//format=format.replace(/w|W/g,Week[date.getDay()]);

		format=format.replace(/dd|DD/,date.getDate()>9?date.getDate().toString():'0' + date.getDate());
		format=format.replace(/d|D/g,date.getDate());

		format=format.replace(/hh|HH/,date.getHours()>9?date.getHours().toString():'0' + date.getHours());
		format=format.replace(/h|H/g,date.getHours());
		format=format.replace(/mm/,date.getMinutes()>9?date.getMinutes().toString():'0' + date.getMinutes());
		format=format.replace(/m/g,date.getMinutes());

		format=format.replace(/ss|SS/,date.getSeconds()>9?date.getSeconds().toString():'0' + date.getSeconds());
		format=format.replace(/s|S/g,date.getSeconds());
		return format;//date.getMonth()+1+"/"+date.getDate()+"/"+date.getFullYear()+" "+date.getHours()+":"+date.getMinutes();
	}

	$.timeStampFormat = function(timestamp,fmt){
		var date = new Date(timestamp);
		return $.dateFormat(date,fmt)
	}

	$.dateFormat = function(date,fmt){
		var o = {
			"M+" : date.getMonth()+1, //月份
			"d+" : date.getDate(), //日
			"h+" : date.getHours()%12 == 0 ? 12 : date.getHours()%12, //小时
			"H+" : date.getHours(), //小时
			"m+" : date.getMinutes(), //分
			"s+" : date.getSeconds(), //秒
			"q+" : Math.floor((date.getMonth()+3)/3), //季度
			"S" : date.getMilliseconds() //毫秒
		};
		var week = {
			"0" : "/u65e5",
			"1" : "/u4e00",
			"2" : "/u4e8c",
			"3" : "/u4e09",
			"4" : "/u56db",
			"5" : "/u4e94",
			"6" : "/u516d"
		};
		if(/(y+)/.test(fmt)){
			fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
		}
		if(/(E+)/.test(fmt)){
			fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[date.getDay()+""]);
		}
		for(var k in o){
			if(new RegExp("("+ k +")").test(fmt)){
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
			}
		}
		return fmt;
	}


}(jQuery));
